<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		[#include "/html/include/easyuicss.html" /]
		<link rel="stylesheet" type="text/css" href="${app }/static/webuploader/css/webuploader.css">
		[#include "/html/include/easyuijs.html" /]
		<script type="text/javascript" src="${app }/static/js/common.utils.js"></script>
		<script type="text/javascript" src="${app }/static/webuploader/dist/webuploader.min.js"></script>
		<style type="text/css">
			img {
				max-width: 200px;
				max-height: 200px;
			}
		</style>
	</head>
	<body>
		<form id="editForm" class="easyui-form" method="post" data-options="novalidate:true">
			<input type="hidden" name="templateId" value="${RequestParameters['id']}" />
			<table class="tblEidt">
				<tr>
					<td class="tdText" style="width:20%;">
						标题<label style="color:red;">*</label>：
					</td>
					<td class="tdInput" style="width:80%;">
						<input class="easyui-textbox" name="title" style="width:80%;" data-options="required:true" />
					</td>
				</tr>
				<tr>
					<td class="tdText">
						摘要<label style="color:red;">*</label>：
					</td>
					<td class="tdInput">
						<input class="easyui-textbox" name="description" style="width:80%;height:80px;" data-options="multiline:true,required:true" />
					</td>
				</tr>
				<tr>
					<td class="tdText">
						图片<label style="color:red;">*</label>：
					</td>
					<td class="tdInput">
						<div id="picker"></div>
						<div id="img"></div>
						<input type="hidden" id="imageUrl" name="imageUrl" data-options="required:true" />
					</td>
				</tr>
				<tr>
					<td class="tdText">
						外部连接<label style="color:red;">*</label>：
					</td>
					<td class="tdInput">
						<input class="easyui-textbox" name="url" style="width:80%;" data-options="required:true" />
					</td>
				</tr>
				<tr>
					<td class="tdText">
						顺序<label style="color:red;">*</label>：
					</td>
					<td class="tdInput">
						<input class="easyui-textbox" name="showOrder" style="width:80%;" data-options="required:true" validType="Number['请填写正确的顺序']" />
					</td>
				</tr>
			</table>
			<div class="edit-btn-group">
				<a href="javascript:;" class="easyui-linkbutton"
				   data-options="iconCls:'icon-ok'" style="width:80px"
				   onclick="save(this);">保存</a>
				&nbsp;&nbsp;
				<a href="javascript:;" class="easyui-linkbutton"
				   data-options="iconCls:'icon-cancel'" style="width:80px"
				   onclick="closeWindow();">关闭</a>
			</div>
		</form>
	</body>
    <script type="text/javascript">
		var index = parent.layer.getFrameIndex(window.name);
		function closeWindow(){
			parent.layer.close(index);
		}
		var uploader = WebUploader.create({
			// 选完文件后，是否自动上传。
			auto: true,
			// swf文件路径
			swf: '${app}/static/webuploader/dist/Uploader.swf',
			method: 'POST',
			// 文件接收服务端。
			server: '${app}/sysmgr/file/upload.do',
			// 设置文件上传域的name
			fileVal: 'files',
			formData: {moduleName: '微信消息', remark: '微信图文消息', downloadType: '2'},
			// 选择文件的按钮。可选。
			pick: {
				id: '#picker',
				label: '点击选择图片'
			},
			// 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
			resize: false,
			// 只允许选择图片文件。
			accept: {
				title: 'Images',
				extensions: 'gif,jpg,jpeg,bmp,png',
				mimeTypes: 'image/*'
			},
			fileNumLimit: 1
		});
		uploader.on('uploadSuccess', function(file, resp) {
			if(resp.result == 1){
				$('#imageUrl').val(resp.filePath);
				$('<img src="${imgSite}/'+resp.filePath+'" />').appendTo('#img');
			}
		});
		function save(obj){
			$(obj).linkbutton('disable');
			$('#editForm').form('submit', {
				url: '${app}/weixin/newsmgr/saveNewsItem.do',
				onSubmit: function () {
					var valid = $(this).form('enableValidation').form('validate');
					if (!valid) {
						$(obj).linkbutton('enable');
					}
					return valid;
				},
				success: function (data) {
					var result = $.parseJSON(data);
					parent.easyui.msgShow('系统提醒', result.msg, 3000, 250, 100);
					$(obj).linkbutton('enable');
					if (result.result == 1) {
						parent.layer.close(index);
					}
				}
			});
		}
    </script>
</html>